import urllib2
import json
import hashlib
import random
import string

android_showdetail_no = 0
android_showdetail_yes = 0

android_apphomepage_v3_no = 0
android_apphomepage_v3_yes = 0

ios_apphomepage_v3_no = 0
ios_apphomepage_v3_yes = 0

ios_showdetail_no = 0
ios_showdetail_yes = 0


def get_md5_value(src):
    myMd5 = hashlib.md5()
    myMd5.update(src)
    myMd5_Digest = myMd5.hexdigest()
    return myMd5_Digest[0:9] + '-' + myMd5_Digest[9:13] + '-' + myMd5_Digest[13:17] + '-' + myMd5_Digest[17:21] + '-' + myMd5_Digest[21:len(myMd5_Digest)]

def random_char(y):
       return ''.join(random.choice(string.ascii_letters) for x in range(y))


for a in xrange(1000):
    android_url = 'http://ab.ymatou.com/ab/?cookieid=' + get_md5_value(random_char(26)) + '&app=%E6%B4%8B%E7%A0%81%E5%A4%B4%E4%B9%B0%E5%AE%B6app&appversion=3.2.7&osid=2&userid=20225712';

    response = urllib2.urlopen(android_url).read()
    hjson = json.loads(response)

    if hjson["app"]["domains"][0]["experiments"][0]["testGroups"][0]["parameters"][0]["value"] == 'no':
        android_showdetail_no += 1
    elif hjson["app"]["domains"][0]["experiments"][0]["testGroups"][0]["parameters"][0]["value"] == 'yes':
        android_showdetail_yes += 1

    for object in hjson["app"]["domains"][0]["experiments"][1]["testGroups"][0]["parameters"]:
        if object["id"] == 105:
            android_apphomepage_v3_yes += 1
        elif object["id"] == 137:
            android_apphomepage_v3_no += 1

for a in xrange(1000):
    ios_url = 'http://ab.ymatou.com/ab/?cookieid=' + get_md5_value(random_char(26)) + '&app=%E6%B4%8B%E7%A0%81%E5%A4%B4%E4%B9%B0%E5%AE%B6app&appversion=3.2.7&osid=1&userid=20225712';

    response = urllib2.urlopen(ios_url).read()
    hjson = json.loads(response)

    if hjson["app"]["domains"][0]["experiments"][0]["testGroups"][0]["parameters"][0]["value"] == 'no':
        ios_showdetail_no += 1
    elif hjson["app"]["domains"][0]["experiments"][0]["testGroups"][0]["parameters"][0]["value"] == 'yes':
        ios_showdetail_yes += 1

    for object in hjson["app"]["domains"][0]["experiments"][1]["testGroups"][0]["parameters"]:
        if object["id"] == 113:
            ios_apphomepage_v3_yes += 1
        elif object["id"] == 133:
            ios_apphomepage_v3_no += 1

print "android_showdetail_yes:" + str(android_showdetail_yes) + ",android_showdetail_no:" + str(android_showdetail_no)
print "android_apphomepage_v3_yes:" + str(android_apphomepage_v3_yes) + ",android_apphomepage_v3_no:" + str(android_apphomepage_v3_no)

print "ios_showdetail_yes:" + str(ios_showdetail_yes) + ",ios_showdetail_no:" + str(ios_showdetail_no)
print "ios_apphomepage_v3_yes:" + str(ios_apphomepage_v3_yes) + ",ios_apphomepage_v3_no:" + str(ios_apphomepage_v3_no)